#include <stdio.h>
#include <map>
using namespace std;

int m, n;
char room[110][110];
map<char, int> vis;
char d;
int result;

int main() {
	scanf("%d %d", &n, &m);
	scanf(" %c", &d);

	for (int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			scanf(" %c", &room[i][j]);
			
			vis[room[i][j]]=0;
		}
	}	
	
	result = 0;

	for (int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			if (vis[room[i][j]]) continue;
			if (room[i][j]=='.') continue;
			if (room[i][j]==d) continue;

			if (j+1<m) {
				if (room[i][j+1]==d) {
					result++;
					vis[room[i][j]]=1; 
					continue;
				}
			}

			if (j-1>=0) {
				if (room[i][j-1]==d) {
					result++;
					vis[room[i][j]]=1; 
					continue;
				}
			}
		
			if (i+1<n) {
				if (room[i+1][j]==d) {
					result++;
					vis[room[i][j]]=1; 
					continue;
				}
			}
		
			if (i-1>=0) {
				if (room[i-1][j]==d) {
					result++;
					vis[room[i][j]]=1; 
					continue;
				}
			}
		}
	}

	printf("%d\n", result);

	return 0;
}
